/*
 * Copyright 2007-2010 Jeremy Brown.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @author <a href="http://jeremy-brown.com">Jeremy Brown</a>
 */

package groovy.prefuse.demos

import prefuse.*
import prefuse.action.*
import prefuse.action.assignment.*
import prefuse.action.layout.graph.*
import prefuse.activity.*
import prefuse.controls.*
import prefuse.data.*
import prefuse.render.*
import prefuse.util.*
import prefuse.visual.*

import groovy.swing.*
import groovy.prefuse.*
import groovy.prefuse.factory.*


def prefuse = new PrefuseBuilder()

def group = "graph"

prefuse.build()
{
	frame(id:"frame", title:'Prefuse Graph Demo 1', defaultCloseOperation:javax.swing.WindowConstants.EXIT_ON_CLOSE)
	{
		pfDisplay(id:"display", size:[720, 500], highQuality:true)
		{
			pfVisualization(id:"vis")
			{
				pfGraph(id:"graph", columnNames:["name"], columnTypes:[String], directed:true, group:group)
				{
					pfNode(["ingest"])
					{
						pfNode(["eat"], id:"eat")
						{
							pfNode(name:"snack", source:true, id:"snack")
							{
								pfNode(name:"nibble")
							}
							pfNode(name:"devour", id:"devour")
						}
						pfNode(name:"drink")
						{
							pfNode(name:"gulp1", source:true, id:"gulp1")
						}
						pfNode(name:"swallow")
						{
							pfNode(name:"gulp2", source:true, id:"gulp2")
						}
					}
				}
				pfLabelRenderer(forNode:true, textField:"name", roundedCorner:[8,8])
				
				pfActionList(id:"color", name:"color")
				{
					pfColorAction(group:"graph.nodes", id:"textColor", name:"textColor", field:VisualItem.TEXTCOLOR, defaultColor:[0,0,0])
					pfColorAction(group:"graph.nodes", id:"nodeColor", name:"nodeColor", field:VisualItem.FILLCOLOR, defaultColor:[190,190,255])
					pfColorAction(group:"graph.edges", id:"edgeColor", name:"edgeColor", field:VisualItem.STROKECOLOR, defaultColor:[200,200,200])
				}
				
				pfActionList(id:"layout", name:"layout", duration:Activity.INFINITY)
				{
					pfForceDirectedLayout(group:group, enforceBounds:true)
					pfAction(new RepaintAction())
				}
			}
		
			pfControl(DragControl)
			pfControl(PanControl)
			pfControl(ZoomControl)
		}
	}
}
	
prefuse.frame.pack()
prefuse.frame.show()

prefuse.vis.run("color")
prefuse.vis.run("layout")

